package com.dodo.blog.ui.util;

import java.io.IOException;
import java.text.MessageFormat;
import java.util.Properties;
import java.util.logging.Logger;

/**
 * @author <a href="mailto:pohorelec@comvai.com">Jozef Pohorelec</a>
 */
public class Localization
{
    private static Logger log = Logger.getLogger( Localization.class.getName() );

    private static Properties properties = new Properties();

    private static final String MESSAGES_PROPERTIES_PATH = "/messages.properties";

    static
    {
        try
        {
            properties.load( Localization.class.getResourceAsStream( MESSAGES_PROPERTIES_PATH ) );
        }
        catch ( IOException e )
        {
            log.severe( "Unable to load message properties for path: " );
        }
    }

    public static String localize( String key, String... params )
    {
        String property = properties.getProperty( key );
        if ( property == null )
        {
            return "##" + key + "##";

        }

        return MessageFormat.format( property, params );
    }

}
